package com.collect.senegal.zhiUtils;

import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

/**
 * 字符串处理工具
 */
public final class StringUtil {
    private static final String TAG = "Strings";

    private StringUtil() {
    }

    /**
     * Judge if a String with a null value.
     *
     * @param src
     * @return
     */
    public final static boolean isNull(String src) {
        return src == null;
    }

    /**
     * Judge if a String with a null value or with zero length.
     *
     * @param src
     * @return
     */
    public final static boolean isEmpty(String src) {
        return src == null || src.length() == 0;
    }

    /**
     * Return whether the string is null or whitespace.
     *
     * @param s The string.
     * @return {@code true}: yes<br> {@code false}: no
     */
    public static boolean isTrimEmpty(final String s) {
        return (s == null || s.trim().length() == 0);
    }

    /**
     * Return whether the string is null or white space.
     *
     * @param s The string.
     * @return {@code true}: yes<br> {@code false}: no
     */
    public static boolean isSpace(final String s) {
        if (s == null) return true;
        for (int i = 0, len = s.length(); i < len; ++i) {
            if (!Character.isWhitespace(s.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    /**
     * Judge if a String with all whitespace.
     *
     * @param src
     * @return
     */
    public final static boolean isBlank(String src) {
        return src != null && "".equals(trimAll(src));
    }

    /**
     * Judge if a String equals value "null".
     *
     * @param src
     * @return
     */
    public final static boolean equalsNull(String src) {
        return src != null && "null".equalsIgnoreCase(trimAll(src));
    }

    /**
     * Ignore all whitespace in a String.
     *
     * @param src
     * @return
     */
    public final static String trimAll(String src) {
        if (src == null) {
            return "";
        }
        return src.replaceAll(" ", "");
    }

    /**
     * Return whether string1 is equals to string2.
     *
     * @param s1 The first string.
     * @param s2 The second string.
     * @return {@code true}: yes<br>{@code false}: no
     */
    public static boolean equals(final CharSequence s1, final CharSequence s2) {
        if (s1 == s2) return true;
        int length;
        if (s1 != null && s2 != null && (length = s1.length()) == s2.length()) {
            if (s1 instanceof String && s2 instanceof String) {
                return s1.equals(s2);
            } else {
                for (int i = 0; i < length; i++) {
                    if (s1.charAt(i) != s2.charAt(i)) return false;
                }
                return true;
            }
        }
        return false;
    }

    /**
     * Return whether string1 is equals to string2, ignoring case considerations..
     *
     * @param s1 The first string.
     * @param s2 The second string.
     * @return {@code true}: yes<br>{@code false}: no
     */
    public static boolean equalsIgnoreCase(final String s1, final String s2) {
        return s1 == null ? s2 == null : s1.equalsIgnoreCase(s2);
    }

    /**
     * Judge if a String with a detail meaning.
     *
     * @param src
     * @return
     */
    public final static boolean isMeaningful(String src) {
        return !isNull(src) && !isBlank(src) && !equalsNull(src);
    }

    /**
     * Change bytes to Hex String in lowercase.
     *
     * @param bytes
     * @return
     */
    public final static String bytes2Hex(byte[] bytes) {
        return byte2Hex(bytes);
    }

    public final static String byte2Hex(byte[] src) {
        if (src == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < src.length; i++) {
            int v = src[i] & 0xFF;
            String hv = Integer.toHexString(v);
            if (hv.length() < 2) {
                sb.append(0);
            }
            sb.append(hv);
        }
        return sb.toString();
    }

    /**
     * Parse a String into an int value, with default value 0 if exception(s) occur.
     *
     * @param input
     * @return
     */
    public final static int toInt(String input) {
        try {
            return Integer.parseInt(input);
        } catch (Exception e) {
            MyLogger.e(e.toString());
        }
        return 0;
    }

    /**
     * Parse a String into a long value, with default value 0L if exception(s) occur.
     *
     * @param input
     * @return
     */
    public final static long toLong(String input) {
        try {
            return Long.parseLong(input);
        } catch (Exception e) {
            MyLogger.e(e.toString());
        }
        return 0;
    }

    /**
     * 匹配json数据，格式化json数据
     *
     * @param jsonStr
     * @return
     */
    public static String formatJson(String jsonStr) {
        int level = 0;
        StringBuffer jsonForMatStr = new StringBuffer();
        for (int i = 0; i < jsonStr.length(); i++) {
            char c = jsonStr.charAt(i);
            if (level > 0 && '\n' == jsonForMatStr.charAt(jsonForMatStr.length() - 1)) {
                jsonForMatStr.append(getLevelStr(level));
            }
            switch (c) {
                case '{':
                case '[':
                    jsonForMatStr.append(c + "\n");
                    level++;
                    break;
                case ',':
                    jsonForMatStr.append(c + "\n");
                    break;
                case '}':
                case ']':
                    jsonForMatStr.append("\n");
                    level--;
                    jsonForMatStr.append(getLevelStr(level));
                    jsonForMatStr.append(c);
                    break;
                default:
                    jsonForMatStr.append(c);
                    break;
            }
        }

        return jsonForMatStr.toString();

    }


    private static String getLevelStr(int level) {
        StringBuffer levelStr = new StringBuffer();
        for (int levelI = 0; levelI < level; levelI++) {
            levelStr.append("\t");
        }
        return levelStr.toString();
    }

    /**
     * Return {@code ""} if string equals null.
     *
     * @param s The string.
     * @return {@code ""} if string equals null
     */
    public static String null2Length0(final String s) {
        return s == null ? "" : s;
    }

    /**
     * Return the length of string.
     *
     * @param s The string.
     * @return the length of string
     */
    public static int length(final CharSequence s) {
        return s == null ? 0 : s.length();
    }

    /**
     * Set the first letter of string upper.
     *
     * @param s The string.
     * @return the string with first letter upper.
     */
    public static String upperFirstLetter(final String s) {
        if (s == null || s.length() == 0) return "";
        if (!Character.isLowerCase(s.charAt(0))) return s;
        return String.valueOf((char) (s.charAt(0) - 32)) + s.substring(1);
    }

    /**
     * Set the first letter of string lower.
     *
     * @param s The string.
     * @return the string with first letter lower.
     */
    public static String lowerFirstLetter(final String s) {
        if (s == null || s.length() == 0) return "";
        if (!Character.isUpperCase(s.charAt(0))) return s;
        return String.valueOf((char) (s.charAt(0) + 32)) + s.substring(1);
    }

    /**
     * Reverse the string.
     *
     * @param s The string.
     * @return the reverse string.
     */
    public static String reverse(final String s) {
        if (s == null) return "";
        int len = s.length();
        if (len <= 1) return s;
        int mid = len >> 1;
        char[] chars = s.toCharArray();
        char c;
        for (int i = 0; i < mid; ++i) {
            c = chars[i];
            chars[i] = chars[len - i - 1];
            chars[len - i - 1] = c;
        }
        return new String(chars);
    }

    /**
     * Convert string to DBC.
     *
     * @param s The string.
     * @return the DBC string
     */
    public static String toDBC(final String s) {
        if (s == null || s.length() == 0) return "";
        char[] chars = s.toCharArray();
        for (int i = 0, len = chars.length; i < len; i++) {
            if (chars[i] == 12288) {
                chars[i] = ' ';
            } else if (65281 <= chars[i] && chars[i] <= 65374) {
                chars[i] = (char) (chars[i] - 65248);
            } else {
                chars[i] = chars[i];
            }
        }
        return new String(chars);
    }

    /**
     * Convert string to SBC.
     *
     * @param s The string.
     * @return the SBC string
     */
    public static String toSBC(final String s) {
        if (s == null || s.length() == 0) return "";
        char[] chars = s.toCharArray();
        for (int i = 0, len = chars.length; i < len; i++) {
            if (chars[i] == ' ') {
                chars[i] = (char) 12288;
            } else if (33 <= chars[i] && chars[i] <= 126) {
                chars[i] = (char) (chars[i] + 65248);
            } else {
                chars[i] = chars[i];
            }
        }
        return new String(chars);
    }

    public static String head(String s, int len) {
        if (len > s.length()) len = s.length();
        return s.substring(0, len);
    }

    public static String tail(String s, int len) {
        if (len > s.length()) len = s.length();
        return s.substring(s.length() - len, s.length());
    }

    /**
     * 去除特殊字符
     *
     * @type method
     * @author liwenjie
     * @creatTime 2019-11-04 14:56
     */
    public static String filterCharToNormal(String oldString) {
        StringBuilder stringBuilder = new StringBuilder();
        int length = oldString.length();
        for (int i = 0; i < length; i++) {
            //遍历传入的String的所有字符
            char codePoint = oldString.charAt(i);
            if (//如果当前字符为常规字符,则将该字符拼入StringBuilder
                    ((codePoint >= 0x4e00) && (codePoint <= 0x9fa5)) ||//表示汉字区间
                            ((codePoint >= 0x30) && (codePoint <= 0x39)) ||//表示数字区间
                            ((codePoint >= 0x41) && (codePoint <= 0x5a)) ||//表示大写字母区间
                            ((codePoint >= 0x61) && (codePoint <= 0x7a))) {//小写字母区间
                stringBuilder.append(codePoint);
            }
        }
        return stringBuilder.toString();
    }

    /**
     * 字符串 千位符
     *
     * @param num
     * @return
     */
    public static String numberTothousandFormatter(String num) {
        try {
            if (TextUtils.isEmpty(num)) {
                return "";
            }
            if (num.contains("-")) {
                return num;
            }
            if (num.equalsIgnoreCase("0.0")) {
                return "0";
            }
            if (num.equalsIgnoreCase("0.00")) {
                return "0";
            }
            BigDecimal resultDecimal = new BigDecimal(num).stripTrailingZeros();
            return (resultDecimal.toPlainString());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return num;
    }

    public static int numberTothousandFormatterInt(String num) {
        try {
            if (TextUtils.isEmpty(num)) {
                return 0;
            }
            if (num.contains("-")) {
                return 0;
            }
            if (num.equalsIgnoreCase("0.0")) {
                return 0;
            }
            if (num.equalsIgnoreCase("0.00")) {
                return 0;
            }
            BigDecimal resultDecimal = new BigDecimal(num).stripTrailingZeros();
            return (resultDecimal.intValue());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static float numberTothousandFormatterFloat(String num) {
        try {
            if (TextUtils.isEmpty(num)) {
                return 0F;
            }
            if (num.contains("-")) {
                return 0F;
            }
            if (num.equalsIgnoreCase("0.0")) {
                return 0F;
            }

            DecimalFormat df1 = new DecimalFormat("0.00");
            BigDecimal bigDecimal = new BigDecimal(num).stripTrailingZeros();
            String formatString = df1.format(bigDecimal);
            BigDecimal resultDecimal = new BigDecimal(formatString).stripTrailingZeros();

            String resultString = resultDecimal.toPlainString() + "";
            if (resultString.equalsIgnoreCase("0.0")) {
                return 0F;
            } else if (resultString.equalsIgnoreCase("0.00")) {
                return 0F;
            }

            return (resultDecimal.stripTrailingZeros().floatValue());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 字符串 保留两位小数点后两位
     */
    public static String numberFormatter00(String num) {
        try {
            if (TextUtils.isEmpty(num)) {
                return "0";
            }
            if (num.contains("-")) {
                return "0";
            }

            DecimalFormat df1 = new DecimalFormat("0.00");
            BigDecimal bigDecimal = new BigDecimal(num).stripTrailingZeros();
            String formatString = df1.format(bigDecimal);
            BigDecimal resultDecimal = new BigDecimal(formatString).stripTrailingZeros();

            String resultString = resultDecimal.toPlainString() + "";
            if (resultString.equalsIgnoreCase("0.0")) {
                resultString = "0";
            } else if (resultString.equalsIgnoreCase("0.00")) {
                resultString = "0";
            } else if (resultString.endsWith(".0")) {
                String[] resultStringAarray = resultString.split("\\.");
                if (resultStringAarray.length > 0) {
                    resultString = resultStringAarray[0];
                }
            } else if (resultString.endsWith(".00")) {
                String[] resultStringAarray = resultString.split("\\.");
                if (resultStringAarray.length > 0) {
                    resultString = resultStringAarray[0];
                }
            }

            return resultString;

        } catch (Exception e) {
            e.printStackTrace();
        }

        return num;
    }

    /**
     * 字符串 保留两位小数点后三位
     */
    public static String numberFormatter000(String num) {
        return numberTothousandFormatter(num);
    }

    /**
     * 字符串 x100后以百分号输出
     */
    public static String numberFormatterPercent(String num) {
        return numberFormatterThousandPercent(num);
    }

    /**
     * 字符串 x100后以百分号输出
     */
    public static String numberFormatterThousandPercent(String num) {
        try {
            if (TextUtils.isEmpty(num)) {
                return "";
            }
            if (num.contains("-")) {
                return num;
            }

            DecimalFormat df1 = new DecimalFormat("0.00");
            BigDecimal bigDecimal = new BigDecimal(num).stripTrailingZeros();
            BigDecimal bigDecimal100 = new BigDecimal("100");
            BigDecimal resultDecimal = bigDecimal.multiply(bigDecimal100);

            String resultString = df1.format(resultDecimal);
            if (resultString.equalsIgnoreCase("0.0")) {
                resultString = "0";
            } else if (resultString.equalsIgnoreCase("0.00")) {
                resultString = "0";
            } else if (resultString.endsWith(".0")) {
                String[] resultStringAarray = resultString.split("\\.");
                if (resultStringAarray.length > 0) {
                    resultString = resultStringAarray[0];
                }
            } else if (resultString.endsWith(".00")) {
                String[] resultStringAarray = resultString.split("\\.");
                if (resultStringAarray.length > 0) {
                    resultString = resultStringAarray[0];
                }
            }

            return (resultString + "%");

        } catch (Exception e) {
            e.printStackTrace();
        }

        return num;
    }

    /**
     * 字符串 x100后以百分号输出
     */
    public static String numberFormatterThousandPercent(BigDecimal bigDecimal) {
        String num = "";
        try {
            if (bigDecimal == null) {
                return "";
            }

            DecimalFormat df1 = new DecimalFormat("0.00");
            BigDecimal bigDecimal100 = new BigDecimal("100");
            BigDecimal resultDecimal = bigDecimal.multiply(bigDecimal100);
            String resultString = df1.format(resultDecimal);

            return (resultString + "%");

        } catch (Exception e) {
            e.printStackTrace();
        }

        return num;
    }

    /**
     * 银行卡号加密显示
     *
     * @type method
     * @author liwenjie
     * @creatTime 2019-11-12 17:21
     */
    public static String bankCardNumberEncryptFormatter(String bankCardNumber) {
        String numStr = bankCardNumber;

        //4位一个单元，取前4与后4
        int sepUnit = 4;
        if (bankCardNumber.length() >= 8) {
            numStr = (bankCardNumber.substring(0, 4));
            numStr = (numStr + " **** ** ");
            numStr = (numStr + bankCardNumber.substring(bankCardNumber.length() - 4));
        }

        return numStr;
    }

    /**
     * 手机号加密显示
     *
     * @type method
     * @author liwenjie
     * @creatTime 2019-11-12 17:21
     */
    public static String phoneNumberEncryptFormatter(String phoneNumber) {
        phoneNumber = StringUtil.safeString(phoneNumber);
        String numStr = phoneNumber;

        //3位一个单元，取前3与后3
        int sepUnit = 3;
        if (phoneNumber.length() >= (2 * 3)) {
            numStr = (phoneNumber.substring(0, sepUnit));
            numStr = (numStr + " *** ");
            numStr = (numStr + phoneNumber.substring(phoneNumber.length() - sepUnit));
        }

        return numStr;
    }

    /**
     * 获取时间戳字符串
     *
     * @type method
     * @author liwenjie
     * @creatTime 2019-11-21 16:44
     */
    public static String getDateTimestamp() {
        Calendar calendar = Calendar.getInstance();
        //获取系统的日期
        //年
        int year = calendar.get(Calendar.YEAR);
        //月
        int month = calendar.get(Calendar.MONTH) + 1;
        //日
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        //获取系统时间
        //小时
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        //分钟
        int minute = calendar.get(Calendar.MINUTE);
        //秒
        int second = calendar.get(Calendar.SECOND);

        String stamp = String.valueOf(year) + String.valueOf(month) + String.valueOf(day) + String.valueOf(hour) + String.valueOf(minute) + String.valueOf(second);

        return stamp;
    }

    /**
     * 字节转字符串
     *
     * @type method
     * @author liwenjie
     * @creatTime 2019-12-23 16:29
     */
    public static String bytesToString(byte[] bytes) {
        if (bytes == null || bytes.length == 0) {
            return null;
        }
        StringBuilder buf = new StringBuilder();
//        for (byte b : bytes) {
//            buf.append(String.format("%02X:", b));
//        }

        int i = bytes.length;
        for (byte b = 0; b < i; b++) {
            byte b1 = bytes[b];
            buf.append(String.format("%02X:", new Object[]{Byte.valueOf(b1)}));
        }
        if (buf.length() > 0) {
            buf.deleteCharAt(buf.length() - 1);
        }
        return buf.toString();
    }

    /**
     * byte数组转hex字符串
     *
     * @param bArr 待转换的Hex字符串
     * @return 转换后的byte数组结果
     */
    public static String bytesToHexString(byte[] bArr) {
        StringBuffer sb = new StringBuffer(bArr.length);
        String sTmp;

        for (int i = 0; i < bArr.length; i++) {
            sTmp = Integer.toHexString(0xFF & bArr[i]);
            if (sTmp.length() < 2) {
                sb.append(0);
            }
            sb.append(sTmp.toUpperCase());
        }
        return sb.toString();
    }


    /**
     * hex字符串转byte数组
     *
     * @param inHex 待转换的Hex字符串
     * @return 转换后的byte数组结果
     */
    public static byte[] hexToByteArray(String inHex) {
        int hexlen = inHex.length();
        byte[] result;
        if (hexlen % 2 == 1) {
            //奇数
            hexlen++;
            result = new byte[(hexlen / 2)];
            inHex = "0" + inHex;
        } else {
            //偶数
            result = new byte[(hexlen / 2)];
        }
        int j = 0;
        for (int i = 0; i < hexlen; i += 2) {
            result[j] = (byte) Integer.parseInt(inHex.substring(i, i + 2), 16);
            j++;
        }
        return result;
    }

    /**
     * 判断是否为数字
     *
     * @param str 待转换的Hex字符串
     * @return 转换后的byte数组结果
     */
    public static boolean isNumeric(String str) {
        str = trimAll(str);
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        for (int i = str.length(); --i >= 0; ) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    /**
     * 判断是否为邮箱
     *
     * @param str 待转换的Hex字符串
     * @return 转换后的byte数组结果
     */
    public static boolean isEmail(String str) {
        str = trimAll(str);
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        String regex = "\\w+@\\w+(\\.\\w{2,9})*\\.\\w{2,9}";
        if (str.matches(regex)) {
            return true;
        }
        return false;
    }

    /**
     * 压缩字符串 zip
     *
     * @type method
     * @author liwenjie
     * @creatTime 2020-03-13 10:32
     */
    public static String stringToGZIP(String sourceString) {

        if (TextUtils.isEmpty(sourceString)) {
            return "";
        }

        String zipString = "";

        try {
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            GZIPOutputStream gzipOutputStream = null;

            gzipOutputStream = new GZIPOutputStream(outputStream);
            gzipOutputStream.write(sourceString.getBytes("utf-8"));
            gzipOutputStream.close();

            byte[] zipBuffer = outputStream.toByteArray();
            zipString = Base64.encodeToString(zipBuffer, Base64.URL_SAFE);
            outputStream.close();

        } catch (IOException e) {
            e.printStackTrace();
        }


        return zipString;
    }

    /**
     * 返回安全字符串
     *
     * @type method
     * @author liwenjie
     * @creatTime 2020/8/14 17:01
     */
    public static String safeString(String sourceString) {
        if (TextUtils.isEmpty(sourceString)) {
            return "";
        }
        return sourceString;
    }

    /**
     * 解压zip 字符串
     *
     * @type method
     * @author liwenjie
     * @creatTime 2020-03-13 10:34
     */
    public static String GZIPToString(String sourceString) {

        if (TextUtils.isEmpty(sourceString)) {
            return "";
        }

        String unZipString = "";

        try {
            byte[] zipBytes = Base64.decode(sourceString.getBytes(), Base64.URL_SAFE);

            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            ByteArrayInputStream inputStream = new ByteArrayInputStream(zipBytes);

            int bufferSize = 1024;
            GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream);

            byte[] buffer = new byte[bufferSize];
            int n;
            while ((n = gzipInputStream.read(buffer)) >= 0) {
                outputStream.write(buffer, 0, n);
            }
            gzipInputStream.close();

            byte[] unZipBuffer = outputStream.toByteArray();
            unZipString = new String(unZipBuffer);

            outputStream.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

        return unZipString;
    }

    public static void testGzip() {

        //原始字符串
        String oriString = "Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib. Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib. Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.Do any additional setup after loading the view, typically from a nib.";
        Log.d(TAG, "---->oriString: " + oriString);
        Log.d(TAG, "---->oriString length: " + oriString.length());

        //压缩字符串
        String zipString = stringToGZIP(oriString);
        Log.d(TAG, "---->zipString: " + zipString);
        Log.d(TAG, "---->zipString length: " + zipString.length());

        //解压字符串
        String unZipString = GZIPToString(zipString);
        ;
        Log.d(TAG, "---->unZipString: " + unZipString);
        Log.d(TAG, "---->unZipString length: " + unZipString.length());
    }

    public static void testGzip(String oriString) {

        //原始字符串
        Log.d(TAG, "---->oriString: " + oriString);
        Log.d(TAG, "---->oriString length: " + oriString.length());

        //压缩字符串
        String zipString = stringToGZIP(oriString);
        Log.d(TAG, "---->zipString: " + zipString);
        Log.d(TAG, "---->zipString length: " + zipString.length());

        //解压字符串
        String unZipString = GZIPToString(zipString);
        ;
        Log.d(TAG, "---->unZipString: " + unZipString);
        Log.d(TAG, "---->unZipString length: " + unZipString.length());
    }
}
